

#import "c_admanager.h"
#import "oc_admanager.h"

#import "SDL2/include/SDL.h"
#import "SDL2/include/SDL_video.h"
#import "SDL2/include/SDL_syswm.h"



OC_Admanager* pAdManager = nil;

static OnPresentFullScreenModal    CallBackOnPresentFullScreen = 0;
static OnDismissFullScreenModal    CallBackOnDismissFullScreen = 0;


void  CAdInit (const char* BannerAdKey,
                  const char* FullScreenAdAppID,
                  const char* FullScreenAdKey,
                  OnPresentFullScreenModal OnPresentCallBack,
                  OnDismissFullScreenModal OnDismissCallBack
                 )
{
    if(pAdManager == nil)
    {
        pAdManager = [OC_Admanager alloc];
    }
    
    CallBackOnPresentFullScreen = OnPresentCallBack;
    CallBackOnDismissFullScreen = OnDismissCallBack;

    
    SDL_SysWMinfo info;
	SDL_VERSION( &info.version );
    
    NSString *pNSKey = [[NSString alloc] initWithUTF8String:BannerAdKey];
    NSString *pNSFSAdAppID = [[NSString alloc] initWithUTF8String:FullScreenAdAppID];
    NSString *pNSFSAdKey = [[NSString alloc] initWithUTF8String:FullScreenAdKey];
    
    /*
     // banner ads are deprecated for now
    SDL_Window* window = SDL_GetFocusWindow();
	if( SDL_GetWindowWMInfo( window, &info ) )
	{
		UIWindow* uiWindow = (UIWindow*)info.info.uikit.window;
		UIView* view = [uiWindow.subviews objectAtIndex:0];
		id nextResponder = [view nextResponder];
		if( [nextResponder isKindOfClass:[UIViewController class]] )
		{
            
            // To Request Ad
            
            UIViewController* viewController = (UIViewController*)nextResponder;     
             
        }
    }
    */
    
    [pAdManager AdInit:nil BannerKey:pNSKey FullScreenAdAppID:pNSFSAdAppID FullScreenAdKey:pNSFSAdKey];
    
    
    
}

void    CRequestFullScreenAd(void)
{
    if(pAdManager)
        [pAdManager RequestFullScreenAd];
}

void  CAd_ShutDown(void)
{
    if(pAdManager)
        [pAdManager ShutDownAd];
}

void  CAd_Hide(void)
{
    [pAdManager Hide];
}

void  CAd_Show(void)
{
    [pAdManager Show];
}

void WillPresentFullScreenModal(void)
{
    if(CallBackOnPresentFullScreen)
    {
        CallBackOnPresentFullScreen();
    }
}

void DidDismissFullScreenModal(void)
{
    if(CallBackOnDismissFullScreen)
    {
        CallBackOnDismissFullScreen();
    }
}

